/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Materials;

import Raytracing.Shaders.Material;
import Raytracing.BRDF.BlendBRDF;
import Raytracing.BRDF.LambertBRDF;
import Raytracing.BRDF.SpecularReflectionBRDF;
import Raytracing.BoundingBox;
import Raytracing.FresnelDielectric;
import Raytracing.Geometry.Triangle;
import Raytracing.Shaders.SolidTexture;
import TweetRay.Box;
import TweetRay.Entity;
import TweetRay.GeometryGenerator;
import Materials.MaterialFactory.Materials;
import TweetRay.UTFWriter;
import java.util.ArrayList;
import processing.core.PVector;

/**
 *
 * @author Matt
 */
public class RoboGenerator extends GeometryGenerator {

    Material[] robomat = new Material[2];

    public RoboGenerator() {
        setName("Red Robot");

        type = MaterialFactory.Materials.ROBOT_GENERATOR.ordinal();
        
        robomat[0] = MaterialFactory.buildMatte("Red Matte", new PVector(.7f, .1f, .1f));
        robomat[1] = MaterialFactory.buildMatte("Yellow Matte", new PVector(.8f, .8f, .1f));
    }

    public void generate(Box bounds, ArrayList<Entity> entities, Material[] shaders) {

        PVector center = bounds.getCentroid();


        ArrayList<Box> temp = new ArrayList();



        temp.add(new Box(32 + (int) center.x, 163, 21 + (int) center.z, 56.0f, 31.0f, 36.0f, -0, 0, -0, robomat, 0));
        temp.add(new Box(0 + (int) center.x, 203, 14 + (int) center.z, 15.0f, 34.0f, 19.0f, -0, 0, -0, robomat, 0));
        temp.add(new Box(21 + (int) center.x, 242, 21 + (int) center.z, 19.0f, 26.0f, 19.0f, -0, 0, -0, robomat, 0));
        temp.add(new Box(33 + (int) center.x, 205, 21 + (int) center.z, 49.0f, 45.0f, 33.0f, -0, 0, -0, robomat, 0));
        temp.add(new Box(64 + (int) center.x, 203, 21 + (int) center.z, 15.0f, 34.0f, 19.0f, -0, 0, -0, robomat, 0));
        //eyes
        temp.add(new Box(47 + (int) center.x, 242, 22 + (int) center.z, 19.0f, 26.0f, 19.0f, -0, 0, -0, robomat, 0));
        temp.add(new Box(42 + (int) center.x, 163, 1 + (int) center.z, 19.0f, 17.0f, 8.0f, -0, 0, -0, robomat, 1));
        temp.add(new Box(19 + (int) center.x, 162, 0  + (int) center.z, 19.0f, 17.0f, 8.0f, -0, 0, -0, robomat, 1));


        //we need to find the extents of the objects that will be added so that
        //we can scale and rotate them to fit into the passed in box
        BoundingBox bb = new BoundingBox();

        for (Box b : temp) {
            for (Triangle tri : b.tris) {
                bb.contain(tri);
            }
        }

        PVector delta = bounds.getCentroid();
        delta.sub(bb.getCentroid());

        delta.mult(1.f);


        float sy = bb.getYDim();
        PVector by = bounds.getLocalXAxis(false);
        float ly = by.mag();
        
        

        for (Box b : temp) {
            b.translate(delta);
            //b.scale(1, sy/ly);
        }

        entities.addAll(temp);

    }

    public void pack(UTFWriter output) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
